<template>
    <div>
      <el-form :model="formData" ref="formData" :rules="formRules" label-position="top" class="form-data">

        <el-form-item label="描述" prop="content">
          <el-input v-model="formData.content" type="text" placeholder="请输入"/>
        </el-form-item>

        <el-form-item label="状态" prop="type">
          <el-switch v-model="formData.type" active-value="1" inactive-value="0" ></el-switch>
        </el-form-item>

        <el-form-item class="form-button">
          <el-button class="but-view" @click="drawerClose">取 消</el-button>
          <el-button class="but-view" type="primary" @click="onSubmit">提 交</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
  export default {
    props: {
      entity: Object,
      status: String
    },
    name: 'WholeSettingForm',
    data() {
      return {
        formData: {
          content: null,
          type: 0,
        },
        formRules: {
          name: [
            { required: true, message: '请输入资源名称', trigger: 'blur' }
          ],
          code: [
            { required: true, message: '请输入资源CODE', trigger: 'blur' }
          ],
          sort: [
            { required: true, message: '请输入排序', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '请输入资源类型', trigger: 'blur' }
          ],
          typeName: [
            { required: true, message: '请输入资源类型名称', trigger: 'blur' }
          ]
        }
      }
    },
    beforeMount() {
      if (this.entity) this.getDetails()
    },
    methods: {
      drawerClose() {
        this.$emit('close')
      },
      async onSubmit() {
        this.$refs.formData.validate(async(valid) => {
          if (!valid) return this.$message.warning('请完善信息')
          const url = this.formData.id ? '/wx/hideDisplay/update' : '/wx/hideDisplay/add'
          await this.$ajax.post(url, this.formData)
          this.$message.success('操作成功!')
          this.$emit('refresh')
          this.drawerClose()
        })
      },
      /**
       * 获取详情
       */
      async getDetails() {
        const res = await this.$ajax.get(`/wx/hideDisplay/info?id=${this.entity.id || ''}`)
        this.formData = res.data
      }
    }
  }
</script>

<style scoped>

</style>
